package logic

import (
	"context"
	"errors"
	"rent-master/models/mysql"

	"rent-master/rent/internal/svc"
	"rent-master/rent/rent"

	"github.com/zeromicro/go-zero/core/logx"
)

type RentShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRentShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RentShowLogic {
	return &RentShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *RentShowLogic) RentShow(in *rent.RentShowRequest) (*rent.RentShowResponse, error) {
	// todo: add your logic here and delete this line

	var Rent mysql.Rent
	err := Rent.RentShow(mysql.DB, in.RentId)
	if err != nil {
		return nil, errors.New("当前房源不存在")
	}

	return &rent.RentShowResponse{
		RentId: int64(Rent.ID),
		Title:  Rent.Title,
		Price:  float32(Rent.Price),
		Area:   Rent.Area,
	}, nil
}
